using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;

namespace ArchSoft
{
    public partial class WatcherReport : Form
    {
        DataSet1 ds = new DataSet1();
        DataSet1.WatcherRow row;
        CrystalReport4 rpt = new CrystalReport4();

        private string _projectFolder;

        public WatcherReport()
        {
            InitializeComponent();
        }

        public string Project
        {
            set { _projectFolder = value; }
        }

        private void WatcherReport_Load(object sender, EventArgs e)
        {
            rpt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rpt;
        }

        public void LoadReport()
        {
            if (File.Exists(_projectFolder))
            {
                DataSet ds2 = new DataSet();
                ds2.ReadXml(_projectFolder);
                DataTable temp = ds2.Tables[0].Copy();

                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    row = ds.Watcher.NewWatcherRow();
                    row["Name"] = temp.Rows[i]["Name"].ToString();
                    row["Element"] = temp.Rows[i]["Element"].ToString();
                    row["Time"] = temp.Rows[i]["Time"].ToString();
                    row["Type"] = temp.Rows[i]["Type"].ToString();
                    row["UserName"] = temp.Rows[i]["UserName"].ToString();
                    ds.Watcher.AddWatcherRow(row);
                }
            }
            else
            {
                row = ds.Watcher.NewWatcherRow();
                row["Name"] = string.Empty;
                row["Element"] = string.Empty;
                row["Time"] = string.Empty;
                row["Type"] = string.Empty;

                ds.Watcher.AddWatcherRow(row);
            }
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            //rpt.SetDataSource(ds);
            //crystalReportViewer1.ReportSource = rpt;
        }
    }
}